package com.wgy.day17.继承性.发红包练习;

import java.util.ArrayList;

/**
 * Created by pc on 2020/11/12 22:08
 * Description: LearningJava
 */

//群主类
public class Manager extends User {
    public Manager() {
    }

    public Manager(String name, int money) {
        super(name, money);
    }

    public ArrayList<Integer> send(int totalMoney, int count) {
        //首先需要一个集合来存储若干个红包的金额
        ArrayList<Integer> redList = new ArrayList<>();

        //首先看一下群主的余额
        int leftMoney = super.getMoney();

        if (leftMoney < totalMoney) {
            System.out.println("余额不足");
            return redList;
        }
        //扣钱,其实就是重新设置余额
        super.setMoney(leftMoney - totalMoney);

        //发红包需要平均拆分count分
        int avg = totalMoney / count;
        int mod = totalMoney % count;//余数.剩下的除不开的零头
        //除不开的零头,包在最后一个红包中
        //下面把红包一个一个放进集合中
        for (int i = 0; i < count - 1; i++) {
            redList.add(avg);
        }
        //最后一个红包
        int last = avg + mod;
        redList.add(last);

        return redList;


    }


}
